<?php
///关于标收费信息的统计
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
  $sfwhere    = " and qtime_h>='$startdate' and  qtime_h<='$enddate'";  
}
$gfileds        = "SUBSTR(qtime_h,1,10 )";
if($MOD=="M"){
    $gfileds    = "SUBSTR(qtime_h,1,7)";    
}   


     
//每日活期总量买入统计
$rows =  $dbselect->GetRows("SELECT SUM(money) as money FROM  23sm_5order WHERE (tid=1 OR tid=2) AND `date_start`='".date_yestoday()."'");

foreach($rows as &$row){
	
	$ctime  =$curday;
    $money = isset($row['money']) ? $row['money'] : 0;    
    
    CTLog::G()->pxxDayReal("sid",1,"活期买入",$money,$ctime);
   
}

//每日活期赎回总量统计
$rows = $dbselect->GetRows("select sum(slice_zong) as money from 23sm_5huoqi_redeem where time_h>='".$startdate."' and time_h<='".$enddate."'");

foreach($rows as &$row){

	$ctime  = $curday;
	 $money = isset($row['money']) ? $row['money'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"活期赎回",$money,$ctime);
	
}

//每日活期赎回本金统计
$rows = $dbselect->GetRows("select sum(slice_benjin) as money from 23sm_5huoqi_redeem where time_h>='".$startdate."' and time_h<='".$enddate."'");

foreach($rows as &$row){

	$ctime  = $curday;
	 $money = isset($row['money']) ? $row['money'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"活期日赎回本金",$money,$ctime);
	
}

//每日活期赎回利息统计
$rows = $dbselect->GetRows("select sum(slice_lixi) as money from 23sm_5huoqi_redeem where time_h>='".$startdate."' and time_h<='".$enddate."'");

foreach($rows as &$row){

	$ctime  = $curday;
	 $money = isset($row['money']) ? $row['money'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"活期日赎回利息",$money,$ctime);
	
}

//每日定期总量买入统计

$rows = $dbselect->GetRows("SELECT SUM(money) as money FROM  23sm_5order WHERE (tid=3 OR tid=4 OR tid=5 OR tid=6) AND `date_start`='".date_yestoday()."'");

foreach($rows as &$row){

	$ctime  = $curday;
	 $money = isset($row['money']) ? $row['money'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"定期买入",$money,$ctime);
	
}

//每日定期到期总还款统计

$rows = $dbselect->GetRows("SELECT SUM(money+yuji_interest) money FROM 23sm_5order WHERE date_end='".date_yestoday()."'");

foreach($rows as &$row){

	$ctime  = $curday;
	 $money = isset($row['money']) ? $row['money'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"定存还款",$money,$ctime);
	
}

//每日定期到期本金还款统计

$rows = $dbselect->GetRows("SELECT SUM(money) money FROM 23sm_5order WHERE date_end='".date_yestoday()."'");

foreach($rows as &$row){

	$ctime  = $curday;
	 $money = isset($row['money']) ? $row['money'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"定期日赎回本金",$money,$ctime);
	
}

//每日定期到期利息还款统计

$rows = $dbselect->GetRows("SELECT SUM(yuji_interest) money FROM 23sm_5order WHERE date_end='".date_yestoday()."'");

foreach($rows as &$row){

	$ctime  = $curday;
	 $money = isset($row['money']) ? $row['money'] : 0;    

		CTLog::G()->pxxDayReal("sid",1,"定期日赎回利息",$money,$ctime);
	
}

//每日产生的体验金利息
// $rows = $dbselect->GetRows("SELECT FORMAT(SUM(FORMAT(yuji_lixi,2)),2) as lixi 
// 							FROM 23sm_tiyanjin_order WHERE time_end>='".date_yestoday()."'");

$rows = $dbselect->GetRows("SELECT FORMAT(SUM(FORMAT(money,2)),2) as lixi
							FROM 23sm_5signin WHERE  signin_date='".date_yestoday()."'");

foreach($rows as &$row){
	$ctime  = $curday;
	$money = isset($row['lixi']) ? $row['lixi'] : 0;    
	
	CTLog::G()->pxxDayReal("sid",1,"日体验金利息",$money,$ctime);
	
}


//日活期产生利息
$rows = $dbselect->GetRows('SELECT SUM(chiyou_slice) AS slice,tid FROM 23sm_5huoqi_trade GROUP BY tid');

foreach($rows as $key=>&$v){
	if($v['tid']==1){
		$doapr = Db::G()->GetNum("select do_apr from 23sm_0type where tid=1 and flag=1");
		$v['zlixi'] = $v['slice']*$doapr/365/100;
	} else if($v['tid']==2){
		$doapr = Db::G()->GetNum("select do_apr from 23sm_0type where tid=2 and flag=1");
		$v['zlixi'] = $v['slice']*$doapr/365/100;
	}
}
	$ctime = $curday;
	$money = $rows[0]['zlixi']+$rows[1]['zlixi'];//得到总的活期利息(包括两个活期产品)
	CTLog::G()->pxxDayReal("sid",1,"日活期产生利息",$money,$ctime);

	

//日定存还款利息
$rows = $dbselect->GetRows("SELECT SUM(yuji_interest) AS money FROM 23sm_5order  WHERE `status`=1 and date_end='".date_yestoday()."'");

foreach($rows as &$row){
	$ctime  = $curday;
	 $money = isset($row['money']) ? $row['money'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"日定存还款利息",$money,$ctime);
	
}

//活期赎回人数
$rows = $dbselect->GetRows("SELECT COUNT(1) as number FROM 23sm_5huoqi_redeem WHERE time_h>='".$startdate."' AND time_h<='".$enddate."'");

foreach($rows as &$row){
	$ctime  = $curday;
	 $number = isset($row['number']) ? $row['number'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"活期赎回人数",$number,$ctime);
	
}

//定存到期回款人数
$rows = $dbselect->GetRows("SELECT count(1) as renshu FROM 23sm_5order WHERE date_end='".date_yestoday()."'"); 

foreach($rows as &$row){
	$ctime  = $curday;
	 $renshu = isset($row['renshu']) ? $row['renshu'] : 0;    
	
		CTLog::G()->pxxDayReal("sid",1,"定存到期回款人数",$renshu,$ctime);
	
}



	
//统计定存待收大于0的人数

// $rows = $dbselect->GetRows("");

//有效投资人数
$rows = $dbselect->GetRows("SELECT COUNT(1) as ren FROM 23sm_5order WHERE order_date='".date_yestoday()."'");

foreach($rows as &$row)
{
	$ctime  = $curday;
	$ren = isset($row['ren']) ? $row['ren'] : 0;

	CTLog::G()->pxxDayReal("sid",1,"有效投资人数",$ren,$ctime);     //

}
	
	





















